<template>
  <div>
    <list ref="list" :disabled="!$permission.canRead()">
      <template #toolbar-left>
        <el-tooltip content="从诺诺系统获取发票信息更新到选中的发票">
          <el-button
            :loading="loading"
            @click="updateInvoiceFromNuoNuo"
            type="primary"
            :disabled="!$permission.canWrite()"
            >更新开票状态</el-button
          >
        </el-tooltip>
      </template>
    </list>
    <edit-dialog ref="editDialog" @close-saved="reload" />
  </div>
</template>

<script>
import list from "@/components/fam/invoice/list";
import editDialog from "@/components/sys/user/editDialog";
import curdMixins from "@/mixins/curd";
import api from "@/api/fam/invoice";

export default {
  name: "sys.user",
  components: {
    list,
    editDialog,
  },
  data() {
    return {
      loading: false,
    };
  },
  mixins: [curdMixins],
  created() {},
  methods: {
    updateInvoiceFromNuoNuo() {
      var rows = this.$refs.list.getCheckedRowsWithMessage();
      if (!rows) {
        return;
      }
      console.log(rows);
      var ids = rows.map((item) => item.id);
      console.log(ids);
      this.$confirm("确定要从诺诺系统获取信息更新当前发票吗？", "提示", {
        type: "warning",
      })
        .then(() => {
          this.loading = true;
          api.updateInvoiceFromNuoNuo(ids).then((res) => {
            this.$refs.list.reload();
            this.loading = false;
          });
        })
        .catch(() => {});
    },
  },
};
</script>